/*
 * 本类作用：工具类
 * 
 * 作者：袁小杰
 * 博客：http://blog.csdn.net/undoner
 * GIT：https://git.oschina.net/undoner
 * QQ：15137281
 * 
 */
package org.mina.util;

public class Tools {

	/**
	 * 整型转byte[]
	 * */
	public static byte[] intToByte(int i) {
		byte[] abyte = new byte[4];
		abyte[0] = (byte) (0xff & i);
		abyte[1] = (byte) ((0xff00 & i) >> 8);
		abyte[2] = (byte) ((0xff0000 & i) >> 16);
		abyte[3] = (byte) ((0xff000000 & i) >> 24);
		return abyte;
	}

	/**
	 * byte[]转整型
	 * */
	public static int bytesToInt(byte[] bytes) {
		int addr = bytes[0] & 0xFF;
		addr |= ((bytes[1] << 8) & 0xFF00);
		addr |= ((bytes[2] << 16) & 0xFF0000);
		addr |= ((bytes[3] << 24) & 0xFF000000);
		return addr;
	}

}
